package org.orarriinae.common.utils.dto;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

/**
 * @author Wang Chengwei
 * @since 1.0
 */
public final class MapUtils {

    private MapUtils() {
    }

    public static <K, V> Map<K, V> collectionToMap(Function<V, K> keyFunc, Collection<V> beans) {
        Map<K, V> map = new HashMap<>();
        for (V bean : beans) {
            K key = keyFunc.apply(bean);
            map.put(key, bean);
        }
        return map;
    }
}
